home *** CD-ROM | disk | FTP | other *** search
/ Mac Magazin/MacEasy 34 / Mac Magazin and MacEasy Magazine CD - Issue 34.iso / Grafik & Text / Alpha ƒ / Tcl / Modes / html.tcl < prev    next >
Text File  |  1997-04-01  |  23KB  |  626 lines

  1. #================================================================================
  2. #
  3. # html.tcl, HTML mode 1.4.1:  macros and bindings for editing HTML documents.
  4. #
  5. #================================================================================
  6. # version 0.24 (16 July 95) by Scott W. Brim <swb1@cornell.edu>
  7. # version 1.0 -- 1.4.1 (April 97) by Johan Linde <jl@theophys.kth.se>
  8. #
  9. # Copyright 1996, 1997 by Johan Linde. 
  10. # This software may be used freely, and distributed freely, as long as 
  11. # the receiver is not obligated in any way by receiving it.
  12. #
  13. # Original ideas taken from Marc Andreesen's html.el and Tom Scavo's latex.tcl.
  14. #
  15. # If you make improvements to this file, please share them!
  16. #
  17. #                                     Johan Linde <jl@theophys.kth.se>
  18. #
  19. #================================================================================
  20.  
  21. # called by Alpha to load HTML in.  
  22. proc htmlDummy {} {}
  23. proc htmlMenu {} {}
  24.  
  25. #===============================================================================
  26. # Global variables and their management
  27. #===============================================================================
  28.  
  29. if {![info exists htmlMenu]} {set htmlMenu    "•135"}
  30.  
  31.  
  32. # Home pages, set the old one if it exists.
  33. if {[info exists homePagePath] && [string length $homePagePath] && 
  34. [info exists HTMLmodeVars(baseURL)] && [string length $HTMLmodeVars(baseURL)]} {
  35.     if {![info exists HTMLmodeVars(basePath)]} {set HTMLmodeVars(basePath) ""}
  36.     newModeVar HTML homePages [list [list [string trimright $homePagePath :] $HTMLmodeVars(baseURL) $HTMLmodeVars(basePath) "index.html"]] 0
  37.     lappend modifiedModeVars {homePages HTMLmodeVars}
  38. } else {
  39.     newModeVar HTML homePages {} 0
  40. }
  41.  
  42.  
  43. # Unsetting old flags and variables which may be defined in arrdefs.tcl 
  44. catch {unset HTMLmodeVars(dlEntries)}
  45. catch {unset HTMLmodeVars(useCtlCmd)}
  46. catch {unset HTMLmodeVars(allContainers)}
  47. catch {unset HTMLmodeVars(quotedAttrs)}
  48. catch {unset HTMLmodeVars(htmlBindPrefix)}
  49. catch {unset HTMLmodeVars(htmlSBindPrefix)}
  50. catch {unset HTMLmodeVars(htmlMenuPrefix)}
  51. catch {unset HTMLmodeVars(htmlSMenuPrefix)}
  52. catch {unset HTMLmodeVars(URLAttrs)}
  53. catch {unset HTMLmodeVars(ColorAttrs)}
  54. catch {unset HTMLmodeVars(elemAttrsForAll)}
  55. catch {unset HTMLmodeVars(useStatusBar)}
  56. catch {unset HTMLmodeVars(baseURL)}
  57. catch {unset HTMLmodeVars(basePath)}
  58.  
  59. # Line width
  60. newModeVar HTML fillColumn 75 0
  61. newModeVar HTML leftFillColumn 0 0
  62. # word breaking and word wrapping
  63. newModeVar HTML wordBreak {\w+} 0
  64. newModeVar HTML wordBreakPreface {(\W)} 0
  65. newModeVar HTML wrapBreak {[\w_]+} 0
  66. newModeVar HTML wrapBreakPreface {([^\w_])} 0
  67.  
  68. # browsers
  69. if {![info exists browserSig]} {set browserSig MOSS}
  70. newModeVar HTML browsers {MOSS MSIE} 0
  71.  
  72. newModeVar HTML wordWrap        1    1
  73. newModeVar HTML prefixString    "<!-- "    0
  74. newModeVar HTML suffixString    " -->"    0
  75.  
  76. # Paths to footer files.
  77. newModeVar HTML footers {} 0
  78. # Tag color
  79. newModeVar HTML tagColor        blue 0
  80. # Should elements be lower case?
  81. newModeVar HTML useLowerCase    0    1
  82. # Should •'s be inserted?
  83. newModeVar HTML    useTabMarks        1    1
  84. # Is <p> a container?
  85. newModeVar HTML pIsContainer    1    1
  86. # Are LI DT and DD containers 
  87. newModeVar HTML lidtAreContainers 0  1
  88. # A list of URLs, cached, to pick from for insertion
  89. newModeVar HTML URLs            {}    0
  90. # A window cache with frames.
  91. newModeVar HTML windows        {}    0
  92. # When browser is launched, should it be brought to front?
  93. newModeVar HTML    browseInForeground    1    1
  94. # Save without asking when sending file to browser?
  95. newModeVar HTML saveWithoutAsking 0 1
  96. # list of commonly used character entities
  97. newModeVar HTML defaultCommonChars {"less than" "greater than" "ampersand"} 0
  98. newModeVar HTML commonChars $HTMLmodeVars(defaultCommonChars) 0
  99. # Which HTML package?
  100. newModeVar HTML htmlPackageToUse 1 0
  101. # Include event handlers in attribute dialog?
  102. newModeVar HTML inclEventHandler 0  1
  103. # Beep when asking for attributes in the status bar?
  104. newModeVar HTML promptNoisily    1    1
  105. # Input from big windows?
  106. newModeVar HTML useBigWindows     1    1
  107. # Check anchors in links
  108. newModeVar HTML checkAnchors 1 1
  109. # Case sensistive link checking?
  110. newModeVar HTML caseSensitive 0 1
  111. # Check links with Big Brother?
  112. newModeVar HTML useBigBrother 0 1
  113. newModeVar HTML checkInFront 1 1
  114. newModeVar HTML useBBoptions 1 1
  115. newModeVar HTML ignoreRemote 0 1
  116. newModeVar HTML ignoreLocal 0 1
  117. # Folder for HTML manual.
  118. newModeVar HTML manualFolder {} 0
  119.  
  120. # JavaScript stuff
  121. newModeVar HTML JavaScriptColoring 0 1
  122. newModeVar HTML JavaScriptColor    magenta 0
  123. newModeVar HTML stringColor green 0
  124. newModeVar HTML JavaCommentColor red 0
  125. newModeVar HTML elecRBrace 0 1
  126. newModeVar HTML elecLBrace 0 1
  127.  
  128. # These mode variables should not appear in the config dialog.
  129.  
  130. set HTMLinvisibleModeVars(htmlPackageToUse) 1
  131. set HTMLinvisibleModeVars(footers) 1
  132. set HTMLinvisibleModeVars(windows) 1
  133. set HTMLinvisibleModeVars(URLs) 1
  134. set HTMLinvisibleModeVars(defaultCommonChars) 1
  135. set HTMLinvisibleModeVars(commonChars) 1
  136. set HTMLinvisibleModeVars(browserSig) 1
  137. set HTMLinvisibleModeVars(homePages) 1
  138. set HTMLinvisibleModeVars(useBigBrother) 1
  139. set HTMLinvisibleModeVars(browsers) 1
  140. set HTMLinvisibleModeVars(manualFolder) 1
  141.  
  142. # These attributes are URLs.
  143. set htmlURLAttr    {HREF= SRC= LOWSRC= ACTION= USEMAP= BACKGROUND= CODEBASE= PLUGINSPAGE=}
  144. # These element attributes are colors
  145. set htmlColorAttr    {BGCOLOR= TEXT= LINK= VLINK= ALINK= COLOR= BORDERCOLOR=}
  146. # These attributes are windows
  147. set htmlWindowAttr {TARGET=}
  148. # Special cases with URLs, colors and windows
  149. set htmlSpecURL {}
  150. set htmlSpecColor {}
  151. set htmlSpecWindow {}
  152. # These elements can be in document HEAD.
  153. set htmlHeadElements1 {BASE ISINDEX LINK META SCRIPT}
  154. set htmlHeadElements3 {BASE ISINDEX LINK META}
  155. # These elements are plug-ins.
  156. set htmlPlugins {EMBED LIVEAUDIO LIVEVIDEO "QUICKTIME MOVIE" "QUICKTIME VR" REALAUDIO}
  157. # HTML mode version
  158. set htmlVersion 1.41
  159.  
  160. # Used by fillParagraph
  161. set htmlParaCommands {html|head|title|body|h[1-6]|p|div|blockquote|center|address|pre|multicol}
  162. append htmlParaCommands {|br|hr|wbr|basefont|ul|ol|li|dir|menu|dl|dd|dt|form|input}
  163. append htmlParaCommands {|select|option|textarea|caption|table|tr|frameset|frame|noframes}
  164. append htmlParaCommands {|map|area|applet|param|script|noscript|base|link|meta|isindex}
  165.  
  166. #
  167. # Internal Globals
  168. #
  169. set htmlCurSel    ""
  170. set htmlIsSel    0
  171. set htmlExtIsLoaded 0
  172. set html32IsLoaded 0
  173. set htmlAdditionExist 0
  174.  
  175. set htmlIsLoaded 1
  176. if { [catch {source "$HOME:Tcl:Modes:htmlEngine.tcl"}] } {
  177.     set htmlIsLoaded 0
  178.     beep
  179.     alertnote "Loading of htmlEngine.tcl failed"
  180. }
  181.  
  182.  
  183. if { [catch {source "$HOME:Tcl:Modes:htmlElems.tcl"}] } {
  184.     set htmlIsLoaded 0
  185.     beep
  186.     alertnote "Loading of htmlElems.tcl failed"
  187. }
  188.  
  189. if { [catch {source "$HOME:Tcl:Modes:htmlUtils.tcl"}] } {
  190.     set htmlIsLoaded 0
  191.     beep
  192.     alertnote "Loading of htmlUtils.tcl failed"
  193. }
  194.  
  195. if { [catch {source "$HOME:Tcl:Modes:htmlMenu.tcl"}] } {
  196.     set htmlIsLoaded 0
  197.     beep
  198.     alertnote "Loading of htmlMenu.tcl failed"
  199. }
  200.  
  201. if {!$HTMLmodeVars(useBigWindows) && [catch {source "$HOME:Tcl:Modes:htmlExtra.tcl"}] } {
  202.     set htmlIsLoaded 0
  203.     beep
  204.     alertnote "Loading of htmlExtra.tcl failed"
  205. }
  206.  
  207. #
  208. # Read custom elements
  209. #
  210.  
  211. proc htmlReadAdditions {} {
  212.     global PREFS htmlElemAttrRequired1 htmlElemAttrOptional1 htmlElemAttrChoices1
  213.     global htmlElemAttrNumber1 htmlElemEventHandler1 htmlElemKeyBinding htmlElemProc
  214.     global htmlExtIsLoaded htmlURLAttr htmlColorAttr htmlWindowAttr htmlPlugins
  215.     global htmlSpecURL htmlSpecColor htmlSpecWindow htmlVersion htmlShownWarning
  216.  
  217.     message "Loading custom elements…"
  218.     
  219.     htmlExtensions
  220.     set htmlExtIsLoaded 1
  221.     rename htmlExtensions ""
  222.     
  223.     if {[catch {open $PREFS:HTMLadditions.tcl r} fid]} {
  224.         alertnote "Could not open the file HTMLAdditions.tcl with your custom elements."
  225.         return
  226.     }
  227.     set additions [read -nonewline $fid]
  228.     close $fid
  229.     set lines [split $additions "\n"]
  230.     set version [lindex $lines 0]
  231.     if {$version == $htmlVersion} {htmlReadAdditions0 $lines; return}
  232.     if {$version > $htmlVersion} {
  233.         regsub "\[^\n\]+" $additions $htmlVersion additions
  234.         set fid [open $PREFS:HTMLadditions.tcl w]
  235.         puts $fid $additions
  236.         close $fid
  237.         htmlReadAdditions0 $lines
  238.         return
  239.     }
  240.     set allattrs [htmlGetAllAttrs]
  241.     set newLines "$htmlVersion\n"
  242.     set changed 0
  243.     set tmpSpecURL ""
  244.     set tmpSpecColor ""
  245.     set tmpSpecWindow ""
  246.     foreach line [lrange $lines 1 end] {
  247.         set elem [lindex $line 0]
  248.         set command [lindex $line 1]
  249.         set elemExists [info exists htmlElemAttrOptional1($elem)]
  250.         if {$elemExists} {
  251.             foreach x [list AttrOptional1 AttrRequired1 AttrNumber1 AttrChoices1 EventHandler1] {
  252.                 if {[info exists htmlElem${x}($elem)]} {
  253.                     set $x [string toupper [set htmlElem${x}($elem)]]
  254.                 } else {
  255.                     set $x ""
  256.                 }
  257.             }
  258.             set attrs [concat $AttrOptional1 $AttrRequired1 $EventHandler1]
  259.             foreach at $attrs {
  260.                 if {[string trimright $at =] == $at} {
  261.                     lappend attrs "${at}="
  262.                 } else {
  263.                     lappend attrs [string trimright $at =]
  264.                 }
  265.             }
  266.         } else {
  267.             set attrs {}
  268.         }
  269.         set var [lindex $command 1]
  270.         foreach ucw [list URL Color Window] {
  271.             if {$var == "html${ucw}Attr"} {
  272.                 set att [lindex $command 2]
  273.                 if {[lsearch -exact [set html${ucw}Attr] $att] >=0} {
  274.                     # Already defined.
  275.                     set changed 1
  276.                 } elseif {[lsearch -exact $allattrs $att] >=0 || [lsearch -exact $allattrs [string trimright $att =]] >=0} {
  277.                     # Used for some other kind of attr.
  278.                     lappend ${ucw}SpecMaybe $att
  279.                     set changed 1
  280.                 } elseif {[lsearch -exact $attrs $att] >= 0} {
  281.                     # Attr already exists for elem.
  282.                     lappend ${ucw}Maybe $att
  283.                     set changed 1
  284.                 } else {
  285.                     append newLines "$line\n"
  286.                 }
  287.             }
  288.             if {$var == "htmlSpec${ucw}"} {
  289.                 set tmpadd [lrange $command 2 end]
  290.                 foreach x $tmpadd {
  291.                     regexp {[^!=]!?=(.*)} $x dum tmp
  292.                     # Only add if attr doesn't exist.
  293.                     if {[lsearch -exact $attrs $tmp] >= 0} {
  294.                         set changed 1
  295.                         set where [lsearch -exact $tmpadd $x]
  296.                         set tmpadd [lreplace $tmpadd $where $where]
  297.                     }
  298.                 }
  299.                 if {[llength $tmpadd]} {
  300.                     append newLines "[list $elem] \{lappend htmlSpec${ucw} $tmpadd\}\n"
  301.                     append tmpSpec${ucw} " " $tmpadd
  302.                 }
  303.             }
  304.         }
  305.         if {[lsearch {htmlURLAttr htmlColorAttr htmlWindowAttr htmlSpecURL \
  306.         htmlSpecColor htmlSpecWindow} $var] < 0} {
  307.             # If element doesn't exist, GO!
  308.             if {!$elemExists} {
  309.                 append newLines "$line\n"
  310.                 regsub "html" $command "tmp" command
  311.                 eval $command
  312.                 continue
  313.             }
  314.             # Skip these vars if element exists.
  315.             if {[string match "htmlElemKeyBinding*" $var] || [string match "htmlElemProc*" $var] ||
  316.             $var == "htmlPlugins"} {
  317.                 set changed 1
  318.                 continue
  319.             }
  320.             regexp {([^\(]+)\(([^\)]+)\)[ ]+(.+)} [lrange $command 1 end] dummy var arg added
  321.             set added [string trimleft [string trimright $added \}] \{]
  322.             foreach c $added {
  323.                 if {$var == "htmlElemAttrChoices1"} {
  324.                     regexp {[^=]*=} $c tmp
  325.                     # Don't add choices if they exist or if attr isn't a choice attr.
  326.                     if {[lsearch -exact $AttrChoices1 $c] >= 0 || ([lsearch -exact $attrs $tmp] >= 0 &&
  327.                     [lsearch $AttrChoices1 "${tmp}*"] < 0) } {
  328.                         set changed 1
  329.                         set where [lsearch -exact $added $c]
  330.                         set added [lreplace $added $where $where]
  331.                     }
  332.                 } else {
  333.                     if {$var == "htmlElemAttrNumber1"} {
  334.                         regexp {[^=]*=} $c tmp
  335.                     } else {
  336.                         set tmp [string toupper $c]
  337.                     }
  338.                     # Don't add attrs which exist.
  339.                     if {[lsearch -exact $attrs $tmp] >= 0} {
  340.                         set changed 1
  341.                         set where [lsearch -exact $added $c]
  342.                         set added [lreplace $added $where $where]
  343.                     }
  344.                 }
  345.             }
  346.             if {[llength $added]} {
  347.                 append newLines "[list $elem] \{lappend ${var}($arg) $added\}\n"
  348.                 regsub "html" $var "tmp" var
  349.                 eval "lappend ${var}($arg) $added"
  350.             }
  351.         }
  352.     }
  353.     foreach ucw [list URL Color Window] {
  354.         if {[info exists ${ucw}SpecMaybe]} {
  355.             foreach m [set ${ucw}SpecMaybe] {
  356.                 foreach e [array names tmpElemAttrRequired1] {
  357.                     if {[lsearch -exact $tmpElemAttrRequired1($e) $m] >= 0 && \
  358.                     [lsearch -exact [set tmpSpec$ucw] "$e!=[string trimright $m =]"] < 0} {
  359.                         append newLines "[list $e] \{lappend htmlSpec${ucw} ${e}=[string trimright $m =]\}\n"
  360.                     } 
  361.                 }
  362.                 foreach e [array names tmpElemAttrOptional1] {
  363.                     if {[lsearch -exact $tmpElemAttrOptional1($e) $m] >= 0 && \
  364.                     [lsearch -exact [set tmpSpec$ucw] "$e!=[string trimright $m =]"] < 0} {
  365.                         append newLines "[list $e] \{lappend htmlSpec${ucw} ${e}=[string trimright $m =]\}\n"
  366.                     } 
  367.                 }
  368.             }
  369.         }
  370.         if {[info exists ${ucw}Maybe]} {
  371.             foreach m [set ${ucw}Maybe] {
  372.                 set foundit 0
  373.                 foreach e [array names tmpElemAttrRequired1] {
  374.                     if {[lsearch -exact $tmpElemAttrRequired1($e) $m] >= 0 && \
  375.                     [lsearch -exact [set tmpSpec$ucw] "$e!=[string trimright $m =]"] < 0} {
  376.                         append newLines "[list $e] \{lappend html${ucw}Attr $m\}\n"
  377.                         set foundit 1
  378.                         break
  379.                     } 
  380.                 }
  381.                 if {$foundit} {continue}
  382.                 foreach e [array names tmpElemAttrOptional1] {
  383.                     if {[lsearch -exact $tmpElemAttrOptional1($e) $m] >= 0 && \
  384.                     [lsearch -exact [set tmpSpec$ucw] "$e!=[string trimright $m =]"] < 0} {
  385.                         append newLines "[list $e] \{lappend html${ucw}Attr $m\}\n"
  386.                         break
  387.                     } 
  388.                 }
  389.             }
  390.         }    
  391.     }
  392.     
  393.     if {$newLines != "$htmlVersion\n"} {htmlReadAdditions0 [split [string trimright $newLines "\n"] "\n"]}
  394.     if {$changed} {
  395.         beep
  396.         if {[lindex [dialog -w 300 -h 270 -b "Clean up" 20 240 100 260 \
  397.         -b "Leave it" 120 240 200 260 -t "Some of your custom elements are supported by this\
  398.         version of HTML mode." 10 10 290 45 -t "Choose 'Clean up' to update your file with custom\
  399.         elements and to avoid this alert next time you run Alpha.\
  400.         If you do so, some elements will not be defined correctly if you go back to\
  401.         a previous version of HTML mode." 10 50 290 150 -t "Choose 'Leave it' to leave your file\
  402.         with custom elements untouched. If you do so, the submenu 'Extend', where you can add new custom\
  403.         elements, will be disabled." 10 160 290 225] 1]} {
  404.             set htmlShownWarning 1
  405.             return
  406.         }
  407.     }
  408.     if {$newLines == "$htmlVersion\n"} {
  409.         removeFile $PREFS:HTMLadditions.tcl
  410.     } else {
  411.         set fid [open $PREFS:HTMLadditions.tcl w]
  412.         puts -nonewline $fid $newLines
  413.         close $fid
  414.     }
  415. }
  416.  
  417. proc htmlReadAdditions0 {lines} {
  418.     global PREFS htmlElemAttrRequired1 htmlElemAttrOptional1 htmlElemAttrChoices1
  419.     global htmlElemAttrNumber1 htmlElemEventHandler1 htmlElemKeyBinding htmlElemProc
  420.     global htmlExtIsLoaded htmlURLAttr htmlColorAttr htmlWindowAttr htmlPlugins
  421.     global htmlSpecURL htmlSpecColor htmlSpecWindow htmlAdditionExist htmlShownWarning
  422.     
  423.     foreach line [lrange $lines 1 end] {
  424.         if {[catch {eval [lindex $line 1]}]} {
  425.             alertnote "There is an error in the file HTMLAdditions.tcl with your custom elements."
  426.             set htmlShownWarning 1
  427.             break
  428.         }
  429.     }
  430.     set htmlAdditionExist 1
  431. }
  432.  
  433. #
  434. # Color support
  435. #
  436.  
  437. proc htmlColorizing {} {
  438.      global HTMLmodeVars HTMLwords htmlElemAttrOptional1 htmlElemAttrRequired1
  439.      global htmlExtIsLoaded htmlElemEventHandler1
  440.      
  441.      set HTMLKeyWords {}
  442.     if {[info exists HTMLwords]} {set HTMLKeyWords [concat $HTMLKeyWords $HTMLwords]}
  443.  
  444.     if {$HTMLmodeVars(JavaScriptColoring)} {
  445.         if {!$htmlExtIsLoaded} {
  446.             htmlExtensions
  447.             set htmlExtIsLoaded 1
  448.             rename htmlExtensions ""
  449.         }
  450.         set allHTMLwords [array names htmlElemAttrOptional1]
  451.         foreach elem $allHTMLwords {
  452.             lappend allHTMLkeywords "<${elem}" "/${elem}"
  453.             if {[info exists htmlElemAttrRequired1($elem)]} {
  454.                 foreach attr $htmlElemAttrRequired1($elem) {
  455.                     if {[lsearch -exact $allHTMLkeywords $attr] < 0} {
  456.                         lappend allHTMLkeywords $attr
  457.                     }
  458.                 }
  459.             }    
  460.             foreach attr $htmlElemAttrOptional1($elem) {
  461.                 if {[lsearch -exact $allHTMLkeywords $attr] < 0} {
  462.                     lappend allHTMLkeywords $attr
  463.                 }
  464.             }
  465.         }
  466.         
  467.         lappend allHTMLkeywords "<INPUT" "<!--" "-->" "FILE=" "FORM=" "#INCLUDE" "/#INCLUDE" "#LASTMODIFIED" "/#LASTMODIFIED"
  468.         set JavaScriptWords {break continue for in function if else new return this var while with true false }
  469.         foreach elem [array names htmlElemEventHandler1] {
  470.             foreach event $htmlElemEventHandler1($elem) {
  471.                 if {[lsearch -exact $JavaScriptWords $event] < 0} {
  472.                     lappend JavaScriptWords $event
  473.                 }
  474.             }
  475.         }
  476.         regModeKeywords -i "<" -i ">"  -I $HTMLmodeVars(tagColor) -e "//" -b "/*" "*/" \
  477.         -c $HTMLmodeVars(JavaCommentColor) \
  478.         -s $HTMLmodeVars(stringColor) -k $HTMLmodeVars(JavaScriptColor) \
  479.         HTML $JavaScriptWords
  480.         regModeKeywords -a -k $HTMLmodeVars(tagColor) \
  481.         HTML [concat $HTMLKeyWords $allHTMLkeywords]    
  482.     } else {
  483.         regModeKeywords -b "<" ">" -c $HTMLmodeVars(tagColor) \
  484.         -k $HTMLmodeVars(tagColor) HTML $HTMLKeyWords
  485.     }
  486. }
  487.  
  488. # Change color when a color variable is changed.
  489. proc htmlChangeColorizing {name1 name2 op} {
  490.     global HTMLmodeVars
  491.     if {$name2 == "JavaScriptColoring" } {
  492.         htmlColorizing
  493.         message "Coloring may not change until you switch to another window."
  494.     } elseif {$name2 == "tagColor"} {
  495.         if {!$HTMLmodeVars(JavaScriptColoring)} {
  496.             regModeKeywords -a -c $HTMLmodeVars(tagColor) HTML
  497.         } else {
  498.             htmlColorizing
  499.             message "Coloring may not change until you switch to another window."
  500.         }
  501.     } elseif {$name2 == "JavaScriptColor" && $HTMLmodeVars(JavaScriptColoring)} {
  502.         htmlColorizing
  503.         message "Coloring may not change until you switch to another window."
  504.     } elseif {$name2 == "JavaCommentColor" && $HTMLmodeVars(JavaScriptColoring)} {
  505.         regModeKeywords -a -c $HTMLmodeVars(JavaCommentColor) HTML
  506.     }
  507.     centerRedraw
  508. }
  509.  
  510. proc htmlShadowAttrUse {name1 name2 op} {
  511.     global HTMLmodeVars htmlMenu
  512.     enableMenuItem $htmlMenu "Use Attributes" [expr !$HTMLmodeVars(useBigWindows)]
  513. }
  514.  
  515. trace variable HTMLmodeVars(tagColor) w htmlChangeColorizing
  516. trace variable HTMLmodeVars(JavaScriptColor) w htmlChangeColorizing
  517. trace variable HTMLmodeVars(JavaScriptColoring) w htmlChangeColorizing
  518. trace variable HTMLmodeVars(JavaCommentColor) w htmlChangeColorizing
  519. trace variable HTMLmodeVars(useBigWindows) w htmlShadowAttrUse
  520. trace variable browserSig w htmlToggleBrowser2
  521.  
  522. # Dialog to set HTML mode variables.
  523. proc HTMLmodifyFlags {} {
  524.     global HTMLmodeVars modifiedModeVars colorInds tcl_var_procs
  525.     set colors {none blue cyan green magenta red white yellow}
  526.     foreach c [array names colorInds] {
  527.         if {[regexp {color} $c]} {lappend colors $c}
  528.     }
  529.     set box "-t {HTML mode Settings} 150 10 300 30 \
  530.     -m {General General JavaScript {Checking links} {Word Wrapping}} 150 40 300 60 \
  531.     -n General \
  532.     -c {Bring browser to front when sending a window to it} $HTMLmodeVars(browseInForeground) 10 70 450 85\
  533.     -c {Save window without asking when sending it to the browser} $HTMLmodeVars(saveWithoutAsking) 10 90 450 105 \
  534.     -c {Set tags in lower case} $HTMLmodeVars(useLowerCase) 10 110 450 125 \
  535.     -c {Use tab marks (•)} $HTMLmodeVars(useTabMarks) 10 130 450 145 \
  536.     -c {<P> has a closing tag </P>} $HTMLmodeVars(pIsContainer) 10 150 450 165 \
  537.     -c {<LI>, <DT> and <DD> have closing tags} $HTMLmodeVars(lidtAreContainers) 10 170 450 185\
  538.     -c {Give attributes in dialog windows, not in the status bar} $HTMLmodeVars(useBigWindows) 10 190 450 205 \
  539.     -c {Beep for each attribute (applies only if you use the status bar)} $HTMLmodeVars(promptNoisily) 10 210 450 225 \
  540.     -t {Color of HTML tags:} 10 240 150 260 \
  541.     -m [list [concat $HTMLmodeVars(tagColor) $colors]] 160 240 310 260 \
  542.     -n JavaScript \
  543.     -c {Color JavaScript keywords} $HTMLmodeVars(JavaScriptColoring) 10 70 450 85\
  544.     -c {Electric left braces} $HTMLmodeVars(elecLBrace) 10 90 450 105 \
  545.     -c {Electric right braces} $HTMLmodeVars(elecRBrace) 10 110 450 125 \
  546.     -c {Include event handlers in attribute dialog} $HTMLmodeVars(inclEventHandler) 10 130 450 145 \
  547.     -t {The settings below apply only if you color JavaScript keywords} 10 160 450 175 \
  548.     -t {Color of JavaScript keywords:} 10 190 210 205 \
  549.     -m [list [concat $HTMLmodeVars(JavaScriptColor) $colors]] 220 190 360 210 \
  550.     -t {Color of JavaScript comments:} 10 220 215 235 \
  551.     -m [list [concat $HTMLmodeVars(JavaCommentColor) $colors]] 220 220 360 240 \
  552.     -t {Color of strings:} 10 250 220 265 \
  553.     -m [list [concat $HTMLmodeVars(stringColor) $colors]] 220 250 360 270 \
  554.     -n {Checking links} \
  555.     -t {These settings apply when you check links with Alpha} 10 70 450 85 \
  556.     -c {Check anchors} $HTMLmodeVars(checkAnchors) 10 90 450 105 \
  557.     -c {Case sensitive checking (slower)} $HTMLmodeVars(caseSensitive) 10 110 450 125 \
  558.     -t {These settings apply when you check links with Big Brother} 10 135 450 150\
  559.     -c {Bring Big Brother to front when checking links} $HTMLmodeVars(checkInFront) 10 155 450 170\
  560.     -c {Use Big Brother's link check options} $HTMLmodeVars(useBBoptions) 10 175 450 190\
  561.     -c {Ignore remote links (if you don't use Big Brother's option)} $HTMLmodeVars(ignoreRemote) 30 195 450 210\
  562.     -c {Ignore local links (if you don't use Big Brother's option)} $HTMLmodeVars(ignoreLocal) 30 215 450 230\
  563.     -n {Word Wrapping} \
  564.     -t {Line width:} 10 70 90 85 -e [list $HTMLmodeVars(fillColumn)] 100 70 140 85 \
  565.     -t characters 145 70 300 85 \
  566.     -t {The variables below determine which characters build up words, and the word wrapping. Normally\
  567.     there is no need to change them. Read about them in general manual if you want to change them.} \
  568.     10 100 450 160 \
  569.     -t wordBreak: 10 170 150 185 -e [list $HTMLmodeVars(wordBreak)] 155 170 450 185 \
  570.     -t wordBreakPreface: 10 195 150 210 -e [list $HTMLmodeVars(wordBreakPreface)] 155 195 450 210 \
  571.     -t wrapBreak: 10 220 150 235 -e [list $HTMLmodeVars(wrapBreak)] 155 220 450 235 \
  572.     -t wrapBreakPreface: 10 245 150 260 -e [list $HTMLmodeVars(wrapBreakPreface)] 155 245 450 260"
  573.     set values [eval [concat dialog -w 460 -h 320 -b OK 20 290 85 310 -b Cancel 110 290 175 310 $box]]
  574.     if {[lindex $values 1]} {return}
  575.     set i 2
  576.     foreach flag [list browseInForeground saveWithoutAsking useLowerCase useTabMarks pIsContainer lidtAreContainers \
  577.         useBigWindows promptNoisily tagColor JavaScriptColoring elecLBrace \
  578.         elecRBrace inclEventHandler JavaScriptColor JavaCommentColor stringColor \
  579.         checkAnchors caseSensitive checkInFront useBBoptions ignoreRemote ignoreLocal \
  580.         fillColumn wordBreak wordBreakPreface wrapBreak wrapBreakPreface] {
  581.         global $flag
  582.         incr i
  583.         set val [lindex $values $i]
  584.         if {$HTMLmodeVars($flag) != $val} {
  585.             set $flag $val
  586.             set HTMLmodeVars($flag) $val
  587.             lappend modifiedModeVars [list $flag HTMLmodeVars]
  588.             
  589.             if {[info exists tcl_var_procs($flag)]} {
  590.                 $tcl_var_procs($flag) $flag
  591.             }
  592.         }
  593.     }
  594. }
  595.  
  596.  
  597. if {$htmlIsLoaded} {
  598.     if {[file exists $PREFS:HTMLadditions.tcl]} {
  599.         if {[catch {htmlReadAdditions}]} {alertnote "An error occured while reading your custom elements."}
  600.     }
  601.     rename htmlReadAdditions ""
  602.     rename htmlReadAdditions0 ""
  603.     htmlBindKeys
  604.     rename htmlBindKeys ""
  605.     message "Building HTML menu…"
  606.     htmlBuildMenu
  607.     htmlColorizing
  608.     # Check that all home page folders exist.
  609.     set tmp_notfind ""
  610.     foreach tmp_hp $HTMLmodeVars(homePages) {
  611.         if {![file exists [lindex $tmp_hp 0]] || ![file isdirectory [lindex $tmp_hp 0]]} {
  612.             alertnote "Can't find the folder for the home page [lindex $tmp_hp 1][lindex $tmp_hp 2]"
  613.             set tmp_notfind "[lindex $tmp_hp 1][lindex $tmp_hp 2]"
  614.         }
  615.     }
  616.     if {$tmp_notfind != ""} {htmlHomePages $tmp_notfind}
  617.     message "HTML initialization complete."
  618.     catch {unset tmp_notfind tmp_hp}
  619. } else {
  620.     message "HTML initialization failed."
  621. }
  622.  
  623. unset htmlIsLoaded
  624.  
  625.